package org.jtao.gbsubject.repository;

import org.jtao.gbsubject.domain.Subject;
import org.jtao.gbsubject.domain.College;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import org.springframework.data.jpa.repository.*;
import org.springframework.data.repository.query.Param;


import java.util.List;
import java.util.Set;

/**
 * Spring Data JPA repository for the Subject entity.
 */
@SuppressWarnings("unused")
@Repository
public interface SubjectRepository extends JpaRepository<Subject, Long> {

    @Query("select distinct subject from Subject subject left join fetch subject.colleges")
    List<Subject> findAllWithEagerRelationships();

    @Query("select subject from Subject subject left join fetch subject.colleges where subject.id =:id")
    Subject findOneWithEagerRelationships(@Param("id") Long id);

    Page<Subject> findAllByCollegesId(Long id, Pageable pageable);

    Subject findOneByName(String name);

}
